<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'
import { getShareInfo } from './data'

onShareAppMessage(wxShare(true, getShareInfo))
onShareTimeline(wxShare(false, getShareInfo))
onAddToFavorites(wxCollect())
// #endif

import TabBar from './components/tab-bar/index.vue'
import Home from './components/home/index.vue'
import Quiz from './components/quiz/index.vue'
import Community from './components/community/index.vue'
import User from './components/user/index.vue'

import SigninMask from './components/home/signin-mask/index.vue'
import LuckyMask from './components/home/lucky-mask/index.vue'
import GuideQuizMask from './components/home/guide-quiz-mask/index.vue'

import { curHomeTarbarKey } from './components/tab-bar/data'
import { imagePath } from '@/libs/file-utils'
import { menuButtonRect, safeArea } from '@/libs/config'
import { showHomeMenu } from './components/home/data'

const bgMap: { [key in T_HomeTarbarKey]: string } = {
  home: imagePath('main/bg-home.jpg'),
  quiz: imagePath('main/bg-quiz.jpg'),
  community: imagePath('main/bg-community.jpg'),
  user: imagePath('main/bg-user.jpg')
}

// import { topMessage } from '@/components/TopMessage/data'
// setTimeout(() => {
//   topMessage.info('测试消息系统', true, 100000)
// })
</script>

<template>
  <PageWrapper
    name="main"
    :showTopBar="false"
    :showBack="false"
    :pageStyle="{ backgroundImage: bgMap[curHomeTarbarKey] }"
    :contentStyle="{
      paddingTop: Math.max(safeArea.top, menuButtonRect.bottom) + 'rpx',
      paddingBottom: '130rpx'
    }"
    @pageClick="showHomeMenu = false"
  >
    <Home v-if="curHomeTarbarKey === 'home'" />
    <Quiz v-if="curHomeTarbarKey === 'quiz'" />
    <Community v-if="curHomeTarbarKey === 'community'" />
    <User v-if="curHomeTarbarKey === 'user'" />

    <template #footer>
      <TabBar />
    </template>
    <template #page>
      <SigninMask />
      <LuckyMask />
      <GuideQuizMask />
    </template>
  </PageWrapper>
</template>
